home *** CD-ROM | disk | FTP | other *** search
- /*
-
- "PShopPal v1.0"
- by Reevan McKay
- ===============
-
- DESCRIPTION:
- ============
- This is a C routine allowing your application to create color tables from
- the data stored in AdobePhotoShop 2.5 & 3.0 clut files.
-
- This routine is "freeware". You may use it, in any form, in any application,
- without condition and without credit. If you find it useful, you might let the
- author know at:
-
- rmckay@chat.carleton.ca
-
-
- USAGE:
- ======
-
- OSErr LoadPalette (FSSpec theFSpec, CTabHandle theCtab,
- unsigned char position, unsigned char colorCount);
-
- theFSpec - a FSSpec pointing to the file you want to open
- theCTab - a CTabHandle to an initialized ColorTable.
- Note that LoadPalette DOES NOT INITIALIZE A COLOR TABLE!
- position - number of entries in the CTabHandle to skip.
- colorCount - number of entries to read from the Photoshop file.
-
- OSErr should == 0L if all goes well. If there is an error, the color table you
- received may contain incorrect data.
-
- /!\ LoadPalette will crash or do weird things if you pass an invalid CTabHandle.
- I suggest initializing one with GetCTable (8). This will create a greyscale colortable
- which you can then modify the entries of. The nice thing about this is that it is
- possible to use several calls to LoadPalette to fill a colortable with data from
- several different files (such as 128 colors from back.pal and another 128 from sprite.pal).
- Also, this routine ASSUMES that you are passing a valid FSSpec to a valid PhotoShop CLUT file,
- in "theFSpec". If you do not, you may encounter abnormal results or unexpected hangs and/or
- crashes, sunspots or earthquakes :p
-
- This routine carries no guarantee as to its fitness for any particular purpose.
- Author is not responsible for any damage to data or hardware arising from use of this routine.
-
- "Checked and cleared. . . Have a better one. . ."
- - Spinner Officer, BladeRunner
-
-
- */
-
- #include "PShopPal.h"
- #include <pictutils.h>
- #ifndef NIL
- #define NIL 0L
- #endif
-
-
- OSErr LoadPalette (FSSpec theFSpec,CTabHandle theCtab,unsigned char position,
- unsigned char colorCount)
- {
- OSErr Err = NIL;
- short refNum;
- Ptr bufferPtr;
- long count;
- short loop;
- long currentPos;
-
- Err = FSpOpenDF (&theFSpec,fsCurPerm,&refNum);
- if(Err)
- return Err;
-
- Err = SetFPos (refNum,fsFromStart,0);
- if(Err)
- return Err;
-
- bufferPtr=NewPtr (6);
-
- for (loop=0;loop<colorCount;loop++)
- {
- count = 1;
- Err = FSRead(refNum,&count, bufferPtr);
- (*theCtab)->ctTable[position].rgb.red = (*((char*)bufferPtr))<<8;
-
- count = 1;
- Err = FSRead(refNum,&count, bufferPtr);
- (*theCtab)->ctTable[position].rgb.green = (*((char*)bufferPtr))<<8;
-
- count = 1;
- Err = FSRead(refNum,&count, bufferPtr);
- (*theCtab)->ctTable[position].rgb.blue = (*((char*)bufferPtr))<<8;
-
- position++;
- };
-
- Err = FSClose (refNum);
- if(Err)
- return Err;
- DisposePtr (bufferPtr);
- return NIL;
- }
-